﻿using System.Collections.Generic;

namespace Marmat.Forms
{
    public class TreeNodeCollection : List<TreeNode>
    {
        private TreeView TreeView;
        private TreeNode TreeNode;

        internal TreeNodeCollection(TreeView TreeView, TreeNode TreeNode)
        {
            this.TreeView = TreeView;
            this.TreeNode = TreeNode;
        }

        public TreeNode Add(string text)
        {
            var nd = new TreeNode();
            nd.Text = text;
            return this.Add(nd);
        }

        public TreeNode Add(string key, string text)
        {
            var nd = new TreeNode();
            nd.Name = key;
            nd.Text = text;
            return this.Add(nd);
        }

        public new TreeNode Add(TreeNode nd)
        {
            nd.m_TreeView = this.TreeView;
            nd.m_Parent = this.TreeNode;
            base.Add(nd);
            this.TreeView?.Invalidate();
            return nd;
        }
    }
}